define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'merchant_cash_template/index' + location.search,
                    add_url: 'merchant_cash_template/add',
                    edit_url: 'merchant_cash_template/edit',
                    del_url: 'merchant_cash_template/del',
                    multi_url: 'merchant_cash_template/multi',
                    import_url: 'merchant_cash_template/import',
                    table: 'merchant_cash_template',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        {
                            field: 'no',
                            title: __('序号'),
                            formatter: function(value, row, index) {
                                //获取每页显示的数量
                                var pageSize = table.bootstrapTable('getOptions').pageSize;
                                //获取当前是第几页
                                var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                                //返回序号，注意index是从0开始的，所以要加上1
                                return pageSize * (pageNumber - 1) + index + 1;
                            },
                            operate: false
                        },
                        { field: 'merchant', title: __('Mer_id') },
                        { field: 'date_type', title: __('Date_type'), searchList: { "1": __('Date_type 1'), "2": __('Date_type 2') }, formatter: Table.api.formatter.normal },
                        { field: 'nums', title: __('Nums') },
                        { field: 'cashMoney', title: __('Cashmoney'), operate: 'BETWEEN' },
                        { field: 'create_time', title: __('Create_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'modify_time', title: __('Modify_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'proceser', title: __('Process_id') },
                        { field: 'creator', title: __('Creator') },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function() {
            Controller.api.bindevent();
        },
        edit: function() {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});